package com.imm.net.http.base.interceptor

import okhttp3.CacheControl
import okhttp3.Interceptor
import okhttp3.Response
import java.util.concurrent.TimeUnit

class HttpInterceptor : Interceptor {

    override fun intercept(chain: Interceptor.Chain): Response {

        // 设置缓存配置
        val cacheBuilder = CacheControl.Builder()
        // 禁止转码
        cacheBuilder.noTransform()
        // 指示客户机可以接收生存期不大于指定时间的响应
        cacheBuilder.maxAge(0, TimeUnit.SECONDS)
        // 指示客户机可以接收超出超时期间的响应消息
        cacheBuilder.maxStale(30, TimeUnit.DAYS)
        // 获取到下层的Request
        val request = chain.request()

        return chain.proceed(request)
    }

}